package com.liuda.workbench.controller;

import com.liuda.commons.constants.Constants;
import com.liuda.commons.domain.ReturnObject;
import com.liuda.commons.utils.DateUtil;
import com.liuda.commons.utils.UUIDUtil;
import com.liuda.settings.domain.User;
import com.liuda.workbench.domain.ActivityRemark;
import com.liuda.workbench.service.ActivityRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
public class ActivityRemarkController {
    @Autowired
    ActivityRemarkService activityRemarkService;
    @ResponseBody
    @RequestMapping("/workbench/activity/createRemark.do")
    public Object createRemark(String remark, String activityId, HttpSession session){
        ReturnObject object=new ReturnObject();
        User user=(User) session.getAttribute(Constants.SESSION_USER);
        ActivityRemark activityRemark=new ActivityRemark();
        activityRemark.setActivityId(activityId);
        activityRemark.setId(UUIDUtil.createId());
        activityRemark.setCreateBy(user.getId());
        activityRemark.setCreateTime(DateUtil.formatDateTime(new Date()));
        activityRemark.setNoteContent(remark);
        activityRemark.setEditFlag("0");
        int count=activityRemarkService.insertRemark(activityRemark);
        if(count<1){
            object.setState("0");
            object.setMsg("系统忙，请稍后重试...");
        }else{
            object.setState("1");
            object.setRetData(activityRemark);
        }
        return object;
    }
    @ResponseBody
    @RequestMapping("/workbench/activity/updateRemark.do")
    public Object updateRemark(ActivityRemark activityRemark,HttpSession session){
        User user=(User)session.getAttribute(Constants.SESSION_USER);
        activityRemark.setEditBy(user.getId());
        activityRemark.setEditTime(DateUtil.formatDateTime(new Date()));
        activityRemark.setEditFlag("1");
        int count=activityRemarkService.updateRemark(activityRemark);
        ReturnObject object=new ReturnObject();
        if(count<1){
            object.setState("0");
            object.setMsg("系统忙，请稍后重试...");
        }else{
            object.setState("1");
            object.setRetData(activityRemark);
        }
        return object;
    }
    @ResponseBody
    @RequestMapping("/workbench/activity/deleteRemark.do")
    public Object deleteRemark(String remarkId){
        int count=activityRemarkService.deleteRemark(remarkId);
        ReturnObject object=new ReturnObject();
        if(count<1){
            object.setState("0");
            object.setMsg("系统忙，请稍后重试！");
        }else{
            object.setState("1");
        }
        return object;
    }
}
